package leetcode

import (
	"strconv"
)

func isPalindromeMethod1(x int) bool {
	if x < 0 {
		return false
	}
	if x < 10 {
		return true
	}
	if x%10 == 0 {
		return false
	}
	str := strconv.Itoa(x)

	for i := 0; i < len(str)/2; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}

	return true
}

func isPalindromeMethod2(x int) bool {
	if x < 0 {
		return false
	}
	if x < 10 {
		return true
	}
	if x%10 == 0 {
		return false
	}
	a, b := x, 0

	for x != 0 {
		b = b*10 + x%10
		x = x / 10
	}

	return a == b
}

func isPalindromeMethod3(x int) bool {
	if x < 0 {
		return false
	}
	if x < 10 {
		return true
	}
	if x%10 == 0 {
		return false
	}
	y := 0

	for x > y {
		y = y*10 + x%10
		x = x / 10
	}

	return x == y || x == y/10
}
